C     COPYRIGHT       NONE.  THIS CODE IS IN THE PUBLIC DOMAIN.
C     FILENAME        GEMINICATCHUPANDRENDEZVOUSPROGRAM/BENCH7.F
C     PURPOSE         THIS IS PART OF THE ORIGINAL 1965 SIMULATION
C                     PROGRAM FOR THE GEMINI 7/6 MISSION
C                     CATCH-UP AND RENDEZVOUS FLIGHT PHASES.
C                     THIS PARTICULAR FILE IS THE MAIN FILE FOR
C                     PROGRAM BENCH7 (ENVIRONMENT FOR MATH FLOW 7),
C                     WITH SUBROUTINES APPEARING IN SEPARATE FILES.
C     WEBSITE         WWW.IBIBLIO.ORG/APOLLO
C     HISTORY         2010-08-14 RSB  BEGAN TRANSCRIBING FROM
C                                     THE SCANNED PDF REPORT.
C
C     REFER TO MAIN.F FOR MORE-DETAILED INTRODUCTORY COMMENTS.
C
C     FROM PAGE 106 OF THE REPORT 
      DIMENSION SLIST(1000),TLIST(1000),DLIST(1000),ILIST(1000),
     1REM(165),VLIST(1)
      DIMENSION CXT(11),CYT(11),CZT(11),CDTWT(11)
      DIMENSION JUMP(9),T(20),JSUB(20),SYM(20,50),ISUB(20,50),A(20,50),
     1B(20,50),D(20,50),TOL(20,50)
      COMMON CDVXSP,CDVYSP,CDVZSP,CDPHSC,CDPSSC,CDTHSC,AKX1  ,AKX2  ,
     1AKX3  ,AKX4  ,AKYI  ,AKY2  ,AKY3  ,AKY4  ,AKZI  ,AKZ2  ,AKZ3  ,
     2AKZ4  ,ASFX  ,ASFY  ,ASFZ  ,CO    ,COI   ,C2    ,C2I   ,CA11  ,
     3CA12  ,CAI3  ,CA21  ,CA22  ,CA23  ,CA31  ,CA32  ,CA33  ,CAPT  ,
     4CAPTI ,CATXBA,CATXBI,CCAB  ,CCABI ,CCAS  ,CCAS1 ,CCK1  ,CCK2  ,
     5CCK3  ,CCK4  ,CCKS  ,CCKF  ,CCKG  ,CCPHIB,CCPSIB,CCPSIR,CCR   ,
     6CCRB  ,CCRBI ,CCRI  ,CCRS  ,CCRSI ,CCTHB ,CCTHR ,CCWSTD,CCWTOL,
     7CCZT  ,CDEL  ,CDRRD ,CDTM  ,CDTW  ,CDTWT ,CDTWX ,CDTX  ,CDV   ,
     8CDVF  ,CDVI  ,CDVT  ,CDVXB ,CDVXM ,CDVXS ,CDVXZ ,CDVYB ,CDVYM ,
     9CDVYS ,CDVYZ ,CDVZB ,CDVZM ,CDVZS ,CDVZZ ,CDXD  ,CDXFD ,CDYD
      COMMON CDYFD ,CDZD  ,CDZFD ,CFX   ,CFY   ,CFZ   ,CM1   ,CM3   ,
     1CM4   ,CM5   ,CM6   ,CNPC  ,CNS   ,CNVX  ,CNVY  ,CNVZ  ,CNYC  ,
     2COEFF ,COINT ,COMGS ,CPHIB ,CPHIBC,CPSBCP,CPSIB ,CPSIBC,CPSIBM,
     3CR1   ,CRA   ,CRLO  ,CRR   ,CRRD  ,CRRG  ,CRRI  ,CRRPI ,CRS   ,
     4CSADPI,CSAPG ,CSAPI ,CSAPR ,CSPHIB,CSPSIB,CSPSIR,CSRDPI,CSRPG ,
     5CSRPI ,CSRPR ,CSRT  ,CSRTI ,CSTD  ,CSTOL ,CSTHB ,CSTHR ,CSTZ  ,
     6CSWSTD,CSWTDL,CT    ,CTD   ,CTDAS ,CTDV  ,CTHB  ,CTHBC ,CTHBCP,
     7CTHBM ,CTLRP ,CTM   ,CTR1  ,CTRR  ,CTTG  ,CTW   ,CTX   ,CUDPHS,
     8CUDPSS,CUDTHS,CWSTD ,CWSTDL,CWTTPR,CX    ,CXM   ,CXRD  ,CXSD  ,
     9CXT   ,CXTD  ,CXZ   ,CY    ,CYM   ,CYRD  ,CYSD  ,CYT   ,CYTD
      COMMON CYZ   ,CZ    ,CZM   ,CZRD  ,CZSD  ,CZT   ,CZTD  ,CZZ   ,
     1DELAY ,DONPRT,DT    ,DUM1  ,DUM2  ,DUM3  ,DUM4  ,DUM5  ,DUM6  ,
     2DUM7  ,DUM8  ,DUM9  ,DUM10 ,DUM11 ,DUM12 ,DUM13 ,DUM14 ,DUM15 ,
     3DUM16 ,DUMI7 ,DUMI8 ,FIN   ,FP    ,FXP   ,FXPP  ,FYP   ,FYPP  ,
     4FZP   ,FZPP  ,GC    ,IC    ,IEXIT ,IOLP  ,IWRITE,K2C   ,KC    ,
     5KWRITE,L     ,LC1   ,LC1J  ,LC2   ,LC3   ,LC4A  ,LC4B  ,LC4C  ,
     6LC4D  ,LC4E  ,LC4F  ,LC4G  ,LC5   ,LC7   ,LC8   ,LC10  ,LCA   ,
     7LCS   ,LCY   ,LDI00 ,LDI10 ,LDI11 ,LDI13 ,LDI20 ,LDI21 ,LDI22 ,
     8LDI25 ,LDI26 ,LDI31 ,LDO01 ,LDO05 ,LDO11 ,LDO12 ,LDO13 ,LDO62 ,
     9LDO63 ,LFDI  ,LQT   ,M     ,N     ,PHIB  ,PINT  ,PSIB  ,RDGD
      COMMON RRDREF,SRAA  ,SREA  ,SW    ,TEST  ,TFTXV ,TFTYV ,TFTZV ,
     1THETAB,TIME  ,TPC   ,TRI   ,TSC   ,TVX   ,TVY   ,TVZ   ,TYC   ,
     2XGRT  ,XGRTD ,XKRDR ,YGRT  ,YGRTD ,ZGRT  ,ZGRTD
      EQUIVALENCE (DELVX,CDVXSP),(DELVY,CDVYSP),(DELVZ,CDVZSP),
     1(CDPHSC,DPHIB),(CDPSSC,DPSIB),(CDTHSC,DTHB),(VLIST,CDVXSP)
      ZZ1=CLOCKF(XX)
      CALL HDA7
      CALL SELFLD
      KT1=5
      KT2=9
      KT3=6
100   READ INPUT TAPE KT1,1032,(REM(I),I=1,165)
      READ INPUT TAPE KT1,1060,NUMRUN,LTOL,NST,NTOL,LSKIP
      WRITE OUTPUT TAPE KT2,1061,NUMRUN,LTOL,NST,NTOL,LSKIP
      NTR=1
      IF (LTOL) 200,155,200
200   IF (LSKIP) 201,202,201
201   READ INPUT TAPE KT1,1062,(JUMP(I),I=1,9)
      WRITE OUTPUT TAPE KT2,1063,(JUMP(I),I=1,9)
202   L=0
      WRITE OUTPUT TAPE KT2,1064
C     
C     FROM PAGE 107 OF THE REPORT 
203   L=L+1
      READ INPUT TAPE KT1,1065,T(L),JS,(SYM(L,K),ISUB(L,K),K=1,JS)
      WRITE OUTPUT TAPE KT2,1066,T(L),(SYM(L,K),ISUB(L,K),K=1,JS)
      JSUB(L)=JS
      IF (NST-L) 155,155,203
155   ZZ=CLOCKF(XX)
      DO 159 I=1,331
159   VLIST(I)=0.
      PTIME=0.
148   READ INPUT TAPE KT1,1000,NDATE1,NDATE2,NDATE3,NRUN1,NRUN2
      I=0
101   I=I+1
      READ INPUT TAPE KT1,1050,SLIST(I),TLIST(I),DLIST(I),ILIST(I)
102   IF (ILIST(I)) 103,103,101
103   J=I
104   WRITE OUTPUT TAPE KT2,1051
      DO 403 I=1,J
      WRITE OUTPUT TAPE KT2,1052,SLIST(I),TLIST(I),DLIST(I),ILIST(I)
403   CONTINUE
      WRITE OUTPUT TAPE KT2,1002,NDATE1,NDATE2,NDATE3,NRUN1,NRUN2
105   I=1
      LS=1
      IF (LSKIP) 214,107,214
214   IF (JUMP(NTR)) 107,107,204
204   CALL SKPN (JUMP(NTR),1,6)
107   IF (TIME-TLIST(I)) 114,108,108
108   K=ILIST(I)
109   VLIST(K)=DLIST(I)
110   I=I+1
      GO TO 107
114   IF (LDO11) 115,122,115
115   LDO11=0
      DELVX=0.
      DELVY=0.
      DELVZ=0.
122   IF (DELVX) 123,124,123
123   LDI31=4095
      GO TO 125
124   LDI31=0
125   IF (DELVY) 126,127,126
126   LDI25=4095
      GO TO 139
127   LDI25=0
139   IF (DELVZ) 140,141,140
140   LDI26=4095
      GO TO 128
141   LDI26=0
128   IF (LDO05) 130,129,130
130   SENSE LIGHT 4
      GO TO 150
129   SENSE LIGHT 0
150   FXP=FXPP*DT/ASFX
      FYP=FYPP*DT/ASFY
      FZP=FZPP*DT/ASFZ
      IF (LDO62) 152,151,152
151   LDI21=0
C
C     FROM PAGE 108 OF THE REPORT 
152   LDO62=4095
      IF (LQT) 153,131,153
153   CALL QUANT (PHIB  ,.036/57.2957795)
      CALL QUANT (THETAB,.036/57.2957795)
      CALL QUANT (PSIB  ,.036/57.2957795)
      CALL QUANT (TRI   ,49.178)
      CALL QUANT (SREA  ,.42594791*.1953125E-2)
      CALL QUANT (SRAA  ,.42594791*.1953125E-2)
      CALL QUANT (FXP   ,.11)
      CALL QUANT (FYP   ,.11)
      CALL QUANT (FZPB  ,.11)
131   CALL GEXECB
      IF (LQT) 154,137,154
154   IF(ABSF(DPHIB)-3./57.2957795) 410,410,411
410   ARG2=.66666667E-1/57.2957795
      GO TO 412
411   ARG2=.66666667E-1*.6/57.2957795
412   CALL QUANT (DPHIB ,ARG2)
      IF(ABSF(DPSIB)-3./57.2957795) 413,413,415
413   ARG2=.66666667E-1/57.2957795
      GO TO 416
415   ARG2=.66666667E-1*.6/57.2957795
416   CALL QUANT (DPSIB ,ARG2)
      IF(ABSF(DTHB )-3./57.2957795) 417,417,418
417   ARG2=.66666667E-1/57.2957795
      GO TO 419
418   ARG2=.66666667E-1*.6/57.2957795
419   CALL QUANT (DTHB  ,ARG2)
137   IF (KWRITE) 138,132,138
138   KWRITE=0
      GO TO 133
132   IF (IWRITE) 133,143,133
143   IF (PINT) 144,205,144
144   IF (TIME-(PTIME+DELAY)) 205,145,145
145   PTIME=PTIME+PINT
133   WRITE OUTPUT TAPE KT2,1029,TIME,NDATE1,NDATE2,NDATE3,NRUN1,NRUN2
      WRITE OUTPUT TAPE KT2,1034
      WRITE OUTPUT TAPE KT2,1030,     REM(  1),CT    ,REM(  2),CA11  ,
     1REM(  3),CA12  ,REM(  4),CA13  ,REM(  5),CDVT  ,REM(  6),CWTTPR,
     2REM(  7),CA21  ,REM(  8),CA22  ,REM(  9),CA23  ,REM( 10),CDVI  ,
     3REM( 11),CDEL  ,REM( 12),CA31  ,REM( 13),CA32  ,REM( 14),CA33  ,
     4REM( 15),CDVF  ,REM( 16),CTM   ,REM( 17),CSPSIR,REM( 18),CFX   ,
     5REM( 19),CX    ,REM( 20),CDVXB ,REM( 21),CDTM  ,REM( 22),CCPSIR,
     6REM( 23),CFY   ,REM( 24),CY    ,REM( 25),CDVYB ,REM( 26),CTDV  ,
     7REM( 27),CSTHR ,REM( 28),CFZ   ,REM( 29),CZ    ,REM( 30),CDVZB ,
     8REM( 31),TSC   ,REM( 32),CCTHR ,REM( 33),CDVXS ,REM( 34),CXM   ,
     9REM( 35),CDVXM
      WRITE OUTPUT TAPE KT2,1030,     REM( 36),CTDAS ,REM( 37),CM1   ,
     1REM( 38),CDVYS ,REM( 39),CYM   ,REM( 40),CDVYM ,REM( 41),CRLO  ,
     2REM( 42),CM3   ,REM( 43),CDVZS ,REM( 44),CZM   ,REM( 45),CDVZM ,
     3REM( 46),CPHIB ,REM( 47),CM4   ,REM( 48),CDV   ,REM( 49),CXZ   ,
     4REM( 50),CDXD  ,REM( 51),CPSIB ,REM( 52),CM5   ,REM( 53),CSTZ  ,
     5REM( 54),CYZ   ,REM( 55),CDYD  ,REM( 56),CTHB  ,REM( 57),CM6   ,
     6REM( 58),CTD   ,REM( 59),CZZ   ,REM( 60),CDZD  ,REM( 61),CUDPHS,
     7REM( 62),COEFF ,REM( 63),CSTD  ,REM( 64),CCRI  ,REM( 65),CXTD  ,
     8REM( 66),CUDPSS,REM( 67),CCK1  ,REM( 68),CSTDL ,REM( 69),C0I   ,
     9REM( 70),CYTD 
C     CONTINUATION LINE 9 ABOVE IS ACTUALLY FROM THE NEXT REPORT PAGE,
C     BUT DIDN'T WANT TO SPLIT IT UP.  FROM PAGE 109 OF THE REPORT --
      WRITE OUTPUT TAPE KT2,1030,     REM( 71),CUDTHS,REM( 72),CCK2  ,
     1REM( 73),CWSTD ,REM( 74),C2I   ,REM( 75),CZTD  ,REM( 76),CDPHSC,
     2REM( 77),CCK3  ,REM( 78),CWSTDL,REM( 79),CCABI ,REM( 80),CXRD  ,
     3REM( 81),CDPSSC,REM( 82),CCK4  ,REM( 83),CNS   ,REM( 84),CCASI ,
     4REM( 85),CYRD  ,REM( 86),CDTHSC,REM( 87),CCK5  ,REM( 88),CTX   ,
     5REM( 89),CCRBI ,REM( 90),CZRD  ,REM( 91),CPSIBC,REM( 92),CCKF  ,
     6REM( 93),CDTX  ,REM( 94),CCRSI ,REM( 95),CDXFD ,REM( 96),CTHBC ,
     7REM( 97),CCKG  ,REM( 98),CRA   ,REM( 99),CATXBI,REM(100),CDYFD ,
     8REM(101),CPSBCP,REM(102),TEST  ,REM(103),CR1   ,REM(104),CAPTI ,
     9REM(105),CDZFD
      WRITE OUTPUT TAPE KT2,1030,     REM(106),CTHBCP,REM(107),FIN   ,
     1REM(108),CDRRD ,REM(109),CSRTI ,REM(110),CXSD  ,REM(111),CPSIBM,
     2REM(112),FP    ,REM(113),RRDREF,REM(114),CRS   ,REM(115),CYSD  ,
     3REM(116),CTHBM ,REM(117),SW    ,REM(118),CRRD  ,REM(119),COMGS ,
     4REM(120),CZSD  ,REM(121),CRRI  ,REM(122),CRRPI ,REM(123),CRRG  ,
     5REM(124),CRR   ,REM(125),CDVXZ ,REM(126),CSAPI ,REM(127),CSADPI,
     6REM(128),CSAPG ,REM(129),CSAPR ,REM(130),CDVYZ ,REM(131),CSRPI ,
     7REM(132),CSRDPI,REM(133),CSRPG ,REM(134),CSRPR ,REM(135),CDVZZ ,
     8REM(136),RDGC  ,REM(137),CTRR  ,REM(138),CTR1  ,REM(139),CTLRP ,
     9REM(140),CDTW
      WRITE OUTPUT TAPE KT2,1019,     REM(141),TVX   ,REM(142),TVY   ,
     1REM(143),TVZ   ,REM(144),TYC   ,REM(145),TPC  
      WRITE OUTPUT TAPE KT2,1036,     REM(146),LC1   ,REM(147),LC4C  ,
     1REM(149),LC10  ,REM(149),LDI00 ,REM(150),IC    ,REM(151),LC1J  ,
     2REM(152),LC4D  ,REM(153),LCA   ,REM(154),LDI21 ,REM(155),KC    ,
     3REM(156),LC2   ,REM(157),LC7   ,REM(158),LCS   ,REM(159),LDO05 ,
     4REM(160),K2C   ,REM(161),LC3   ,REM(162),LC8   ,REM(163),N     ,
     5REM(164),M     ,REM(165),L
      WRITE OUTPUT TAPE KT2,1031,(CXT(I),CYT(I),CZT(I),CDTWT(I),I=1,11)
      WRITE OUTPUT TAPE KT2,1004,CDVXSP,CDVYSP,CDVZSP
205   IF (LTOL) 206,134,206
206   IF (NST-LS) 134,207,207
207   IF (TIME-T(LS)) 134,208,208
208   JS=JSUB(LS)
      DO 209 K=1,JS
      IS=ISUB(LS,K)
      A(LS,K)=VLIST(IS)
209   CONTINUE
      LS=LS+1
134   TIME=TIME+DT
      IF (SENSE SWITCH 6) 142,135
142   PRINT 1053,TIME ,I
135   IF (ILIST(I)) 210,210,107
210   DO 211 L=1,NST
      JS=JSUB(L)
211   WRITE TAPE KT3,(A(L,K),K=1,JS)
      END FILE KT3
136   WRITE OUTPUT TAPE KT2,1001,NRUN1,NRUN2
      PRINT 1003,NRUN1,NRUN2
      ZZ=CLOCKF(XX)
157   IF (NUMRUN-NTR) 213,213,212
212   NTR=NTR+1
      GO TO 155
C
C     FROM PAGE 110 OF THE REPORT 
213   IF (LTOL) 215,158,215
215   REWIND KT3
      NTR=0
      DO 216 L=1,NST
      JS=JSUB(L)
216   READ TAPE KT3,(A(L,K),K=1,JS)
217   CALL SKPN (1,1,6)
      DO 221 L=1,NST
      JS=JSUB(L)
221   READ TAPE KT3,(B(L,K),K=1,JS)
      DO 222 L=1,NST
      JS=JSUB(L)
      DO 222 K=1,JS
      D(L,K)=ABSF(A(L,K)-B(L,K))
222   TOL(L,K)=TOL(L,K)+D(L,K)
      NTR=NTR+1
      WRITE OUTPUT TAPE KT2,1067,NTR
      DO 219 L=1,NST
      JS=JSUB(L)
219   WRITE OUTPUT TAPE KT2,1068,T(L),(SYM(L,K),D(L,K),K=1,JS)
      IF (NTOL-NTR) 220,220,217
220   WRITE OUTPUT TAPE KT2,1069
      DO 218 L=1,NST
      JS=JSUB(L)
218   WRITE OUTPUT TAPE KT2,1068,T(L),(SYM(L,K),TOL(L,K),K=1,JS)
158   ZZ2=CLOCKF(XX)
      ZZ3=ZZ2-ZZ1
      PRINT 1005,ZZ3
      WRITE OUTPUT TAPE KT2,1005,ZZ3
156   CALL EXIT
1000  FORMAT (11X,I2,1X,I2,1X,I2,10X,A6,A6)
1001  FORMAT (12H END OF RUN ,A6,A6/1H1)
1002  FORMAT (6H DATE ,I2,1H/,I2,1H/,I2,10X,4HRUN ,A6,A6//)
1003  FORMAT (12H END OF RUN ,A6,A6)
1004  FORMAT (1H0,12HIVI READINGS,8X,9HAFT - FWD,13X,5HL - R,14X,
     17HUP - DN/13X,3E20.8)
1005  FORMAT (1H0,16HTHIS PROGRAM RAN,-2PF9.2,9H MINUTES.)
1019  FORMAT (5(1H ,A6,O14,3X))
1029  FORMAT (1H1,7HTIME = ,E15.8,9H SECONDS.,52X,5HDATE ,I2,1H/,I2,1H/,
     1I2,7X,4HRUN ,A6,A6/)
1030  FORMAT (5(1H ,A6,E15.8,2X))
1031  FORMAT (1H0,36H11 VALUES EACH OF X,Y,Z, AND DELTA T//(1H ,4E20.8))
1032  FORMAT (12A6)
1034  FORMAT (1H ,40HSIMULATED COMPUTER OUTPUTS ON THIS PAGE.//)
1036  FORMAT (5(1H ,A6,I6,11X))
1050  FORMAT (A6,2E15.8,I4)
1051  FORMAT (1H1,6HSYMBOL,8X,4HTIME,14X,4HDATA,10X,1HI//)
1052  FORMAT (1H ,A6,2E18.8,I6)
1053  FORMAT (1H ,6HTIME =,E15.8,6H   I =,I4)
1060  FORMAT (5(7X,I3))
1061  FORMAT (1H1,7HNUMRUN=,I3,7H  LTOL=,I3,7H   NST=,I3,7H  NTOL=,I3,
     17H LSKIP=,I3)
1062  FORMAT (9I3)
1063  FORMAT (1H0,8HJUMP(1)=,I3,2X,8HJUMP(2)=,I3,2X,8HJUMP(3)=,I3,2X,
     18HJUMP(4)=,I3,2X,8HJUMP(5)=,I3,2X,8HJUMP(6)=,I3,2X,8HJUMP(7)=,I3,
     22X,8HJUMP(8)=,I3,2X,8HJUMP(9)=,I3)
C
C     FROM PAGE 111 OF THE REPORT 
1064  FORMAT (1H0//11H TIME (SEC),6X,22HSYMBOLS AND SUBSCRIPTS)
1065  FORMAT (F9.0,I3,6(1X,A6,I3)/(3X,A6,I3,1X,A6,I3,1X,A6,I3,1X,A6,I3,
     11X,A6,I3,1X,A6,I3,1X,A6,I3))
1066  FORMAT (1H0,F12.0,9(2X,A6,I4)/(15X,A6,I4,2X,A6,I4,2X,A6,I4,2X,A6,
     1I4,2X,A6,I4,2X,A6,I4,2X,A6,I4,2X,A6,I4,2X,A6,I4))
1067  FORMAT (1H1,29HTOLERANCES FROM TOLERANCE RUN,I3//5X,11HSAMPLE TIME
     1,20X,22HSYMBOLS AND TOLERANCES)
1068  FORMAT (1H0,F16.1,6X,4(3X,A6,E15.8)/(26X,A6,E15.8,3X,A6,E15.8,3X,
     1A6,E15.8,3X,A6,E15.8))
1069  FORMAT (1H1,25X,16HFINAL TOLERANCES//5X,11HSAMPLE TIME,20X,
     122HSYMBOLS AND TOLERANCES)
      END(1,1,0,0,0,0,1,1,0,0,0,0,0,0,0)
